<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>删除squid缓存 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>删除squid缓存</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Squid/">Squid</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如何清除squid 缓存</p>
<ol>
<li>首先在squid 的主配置文件中添加acl 列表，并允许受信任的主机有权限清除缓存  </li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">acl managercache src 192.168.1.145 127.0.0.1</div><div class="line">acl Purge method PURGE</div><div class="line">http_access allow managercache Purge</div><div class="line">http_access deny Purge</div></pre></td></tr></table></figure>
<ol>
<li>清除squid 中一条缓存  </li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="built_in">local</span>/squid/bi/squidclient -h 192.168.1.145 -p80 -m PURGE http://www.linuxidc.com/404.html</div></pre></td></tr></table></figure>
<ol>
<li>批量清除squid 缓存中的文件</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;脚本如下   </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#!/bin/sh</span></div><div class="line"> squidcache_path=<span class="string">"/usr/local/squid/var/cache/"</span></div><div class="line"> squidclient_path=<span class="string">"/usr/local/squid/bin/squidclient"</span></div><div class="line"> grep -a -r <span class="variable">$1</span> <span class="variable">$squidcache_path</span>/* | strings | grep <span class="string">"http:"</span> | awk -F<span class="string">'http:'</span> <span class="string">'&#123;print "http:"$2;&#125;'</span> &gt; cache_list.txt</div><div class="line"> <span class="keyword">for</span> url <span class="keyword">in</span> `cat cache_list.txt`; <span class="keyword">do</span></div><div class="line">     <span class="variable">$squidclient_path</span> -m PURGE -p80 <span class="variable">$url</span></div><div class="line"> <span class="keyword">done</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注：</p>
<ul>
<li>squidcache_path 是squid 缓存路径</li>
<li>squidclient_path 是squidclient 命令的 路径</li>
<li>-p  是指定squid 监听的端口</li>
</ul>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;给clearcache.sh 执行权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#chmod +x clearcache.sh</span></div></pre></td></tr></table></figure>
<ol>
<li>使用方法</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用法：</p>
<ul>
<li>清除所有Flash缓存（扩展名.swf）：      </li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./clear_squid_cache.sh swf</div></pre></td></tr></table></figure>
<ul>
<li>清除URL中包含sina.com.cn的所有缓存：</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./clear_squid_cache.sh sina.com.cn</div></pre></td></tr></table></figure>
<ul>
<li>清除文件名为zhangyan.jpg的所有缓存：</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">./clear_squid_cache.sh zhangyan.jpg</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Squid/14. 删除squid缓存/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
